package com.xb.p25_intentservice;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    Button button1;
    Button button2;
    Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button1=findViewById(R.id.btn_start1);
        button2=findViewById(R.id.btn_start2);

        button1.setOnClickListener(new MyClick());
        button2.setOnClickListener(new MyClick());

    }

    //内部类实现事件监听
    public class MyClick implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            intent = new Intent(MainActivity.this,MyIntentService.class);
            switch (view.getId()){
                case R.id.btn_start1:
                    intent.putExtra("number","1");
                    break;
                case R.id.btn_start2:
                    intent.putExtra("number","2");
                    break;
            }
            startService(intent);
        }
    }

}